%# -*- C -*-
%# Copyright (c) 2017 Urabe, Shyouhei.  All rights reserved.
%#
%# This file is a part of  the programming language Ruby.  Permission is hereby
%# granted, to either  redistribute and/or modify this file,  provided that the
%# conditions mentioned  in the  file COPYING  are met.   Consult the  file for
%# details.
%
% zjit_insns, insns = RubyVM::Instructions.partition { |i| i.name.start_with?('zjit_') }
%
CONSTFUNC(MAYBE_UNUSED(static int insn_len(VALUE insn)));

RUBY_SYMBOL_EXPORT_BEGIN /* for debuggers */
extern const uint8_t rb_vm_insn_len_info[VM_INSTRUCTION_SIZE];
RUBY_SYMBOL_EXPORT_END

#ifdef RUBY_VM_INSNS_INFO
const uint8_t rb_vm_insn_len_info[] = {
% insns.each_slice(23) do |row|
    <%= row.map(&:width).join(', ') -%>,
% end
#if USE_ZJIT
% zjit_insns.each_slice(23) do |row|
    <%= row.map(&:width).join(', ') -%>,
% end
#endif
};

ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_len_info);
#endif

int
insn_len(VALUE i)
{
    return rb_vm_insn_len_info[i];
}
